# -*- coding: utf-8 -*-
from google.appengine.api import memcache
from datetime import datetime, date
import re
import string
import sys
import random
import logging
from google.appengine.api import users

def _string_to_slug(s):
	#raw_data = el2gr(s)
	raw_data = s
    # normalze string as proposed on http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/251871
    # by Aaron Bentley, 2006/01/02
	try:
		import unicodedata
		raw_data = unicodedata.normalize('NFKD', raw_data.decode('utf-8', 'replace')).encode('ascii', 'ignore')
	except:
		pass
	return re.sub(r'[^a-z0-9-]+', '-', raw_data.lower()).strip('_')

def debug(text=''):
	logging.debug(text)
	if text == 'clear':
		memcache.delete("debug")
		return
	contents = memcache.get("debug")
	if text == ''or text is None:
		return contents
	if contents is None:
		memcache.add("debug", text, 900)
	else:
		text = contents + "<br>" + text
		memcache.set("debug", text)
	return text

def printDebug():
	tempDebug = debug()
	debug('clear')
	return tempDebug

def check_url_lang(tag):
	#if tag in
	return



def sessionUser(user=None):
	if user == 'clear':
		memcache.delete("user")
		#debug('return1')
		return None
	sesUser = memcache.get("user")
	if user is '' or user is None:
		#debug('return2 = ' + str(sesUser))
		return sesUser
	elif sesUser is None:
		memcache.add("user", user, 900)
		#debug('return3')
		return user
	else:
		memcache.set("user", user)
		#debug('return4')
		return user